package com.ruoyi.system.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.KfnCustomerVo;
import com.ruoyi.system.domain.bo.KfnCustomerBo;
import com.ruoyi.system.service.IKfnCustomerService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * KFN客户管理
 *
 * @author Panda
 * @date 2023-12-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/customer")
public class KfnCustomerController extends BaseController {

    private final IKfnCustomerService iKfnCustomerService;

    /**
     * 查询KFN客户管理列表
     */
    @SaCheckPermission("system:customer:list")
    @GetMapping("/list")
    public TableDataInfo<KfnCustomerVo> list(KfnCustomerBo bo, PageQuery pageQuery) {
        return iKfnCustomerService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出KFN客户管理列表
     */
    @SaCheckPermission("system:customer:export")
    @Log(title = "KFN客户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(KfnCustomerBo bo, HttpServletResponse response) {
        List<KfnCustomerVo> list = iKfnCustomerService.queryList(bo);
        ExcelUtil.exportExcel(list, "KFN客户管理", KfnCustomerVo.class, response);
    }

    /**
     * 获取KFN客户管理详细信息
     *
     * @param customerId 主键
     */
    @SaCheckPermission("system:customer:query")
    @GetMapping("/{customerId}")
    public R<KfnCustomerVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long customerId) {
        return R.ok(iKfnCustomerService.queryById(customerId));
    }

    /**
     * 新增KFN客户管理
     */
    @SaCheckPermission("system:customer:add")
    @Log(title = "KFN客户管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody KfnCustomerBo bo) {
        return toAjax(iKfnCustomerService.insertByBo(bo));
    }

    /**
     * 修改KFN客户管理
     */
    @SaCheckPermission("system:customer:edit")
    @Log(title = "KFN客户管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody KfnCustomerBo bo) {
        return toAjax(iKfnCustomerService.updateByBo(bo));
    }

    /**
     * 删除KFN客户管理
     *
     * @param customerIds 主键串
     */
    @SaCheckPermission("system:customer:remove")
    @Log(title = "KFN客户管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{customerIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] customerIds) {
        return toAjax(iKfnCustomerService.deleteWithValidByIds(Arrays.asList(customerIds), true));
    }
}
